package home;

import org.apache.wicket.ajax.AjaxRequestTarget;
import org.apache.wicket.markup.html.WebPage;
import org.apache.wicket.markup.html.basic.Label;
import org.apache.wicket.spring.injection.annot.SpringBean;
import panels.BodyPanel;
import panels.DynamicMenu;
import panels.MyPanel;
import services.GeneralService;
import staticmenus.StaticMenu;

@SuppressWarnings("serial")
public class Home extends WebPage{
	
	@SpringBean(name = "service.general")
	private GeneralService generalService;
	
	private DynamicMenu menu;
	
	private StaticMenu staticMenu;
	
	private BodyPanel body;
	
	private Label error;
	
	@Override
	protected void onInitialize() {
		super.onInitialize();
		this.add(new Label("company", "Neumaticos Dorrego"));
		setErrorLabel();
		this.createDynamicMenu();
		this.createBodyPanel();
		this.createStaticMenu();
	}

	private void setErrorLabel() {
		this.setError(new Label("error", ""));
		this.add(this.getError());
	}

	private void createStaticMenu() {
		StaticMenu staticMenu = new StaticMenu(this);
		this.configurePanel(staticMenu);
		this.setStaticMenu(staticMenu);
	}

	private void createBodyPanel() {
		BodyPanel body = new BodyPanel(this);
		this.configurePanel(body);
		this.setBody(body);
	}

	private void createDynamicMenu() {
		DynamicMenu menu = new DynamicMenu(this);
		this.configurePanel(menu);
		this.setMenu(menu);
	}
	
	private void configurePanel(MyPanel panel){
		this.add(panel);
		panel.setOutputMarkupId(true);
		panel.setOutputMarkupPlaceholderTag(true);
	}

	/**
	 * Cambia un panel en la pagina principal
	 * @param target
	 * @param panel
	 */
	public void changePanel(AjaxRequestTarget target, MyPanel panel) {
		panel.setOutputMarkupId(true);
	    panel.setOutputMarkupPlaceholderTag(true);
		target.add(panel);
	}

//------------------Sett&Gett-----------------------
	
	public DynamicMenu getMenu() {
		return menu;
	}


	public void setMenu(DynamicMenu menu) {
		this.menu = menu;
	}


	public BodyPanel getBody() {
		return body;
	}


	public void setBody(BodyPanel body) {
		this.body = body;
	}


	public GeneralService getGeneralService() {
		return generalService;
	}


	public void setGeneralService(GeneralService generalService) {
		this.generalService = generalService;
	}

	public StaticMenu getStaticMenu() {
		return staticMenu;
	}

	public void setStaticMenu(StaticMenu staticMenu) {
		this.staticMenu = staticMenu;
	}

	public Label getError() {
		return error;
	}

	public void setError(Label error) {
		this.error = error;
	}



}
